package org.leetcode.middle.leetcode343;

public class Solution {

    public int integerBreak2(int n) {

        int[] dp = new int[n + 1];
        dp[2] = 1;

        for (int i = 3; i <= n; i++) {
            int currMax = 0;
            for (int j = 1; j < i; j++) {
                currMax = Math.max(currMax, Math.max(j * (i - j), j * dp[i - j]));
            }
            dp[i] = currMax;
        }

        return dp[n];
    }

    public int integerBreak(int n) {

        int[] dp = new int[n + 1];

        dp[2] = 1;

        for (int i = 3; i <= n; i++) {
            for (int j = 1; j <= i - j; j++) {
                int mayMAX = Math.max(j * (i - j), j * dp[i - j]);
                dp[i] = Math.max(dp[i], mayMAX);
            }
        }

        return dp[n];

    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.integerBreak(3);
    }
}
